package com.hdu.cglib;

import com.hdu.IStudentService;
import com.hdu.StudentService;
import net.sf.cglib.core.DebuggingClassWriter;
import net.sf.cglib.proxy.Enhancer;

public class Main {

    public static void main(String[] args) {
        // 这句代码的意思是将生成的代理类的字节码文件写入到指定的目录下
        System.setProperty(
                DebuggingClassWriter.DEBUG_LOCATION_PROPERTY,
                "D:\\cglib_proxy"
        );
        CglibInterceptor cglibInterceptor = new CglibInterceptor(new StudentService());
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(StudentService.class);
        enhancer.setCallback(cglibInterceptor);
        IStudentService studentService = (StudentService) enhancer.create();
        studentService.save("张三");
    }
}
